﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Web.Core.ViewModels.Extensions
{
	public abstract class ViewModelExtension
	{
		protected internal abstract bool IsFor(BaseModel model);
		protected internal abstract void Initialize(BaseModel model);
	}

	public abstract class ViewModelExtension<TModel> : ViewModelExtension where TModel : BaseModel
	{
		protected internal override bool IsFor(BaseModel model)
		{
			return model is TModel;
		}

		protected internal abstract void DoInitialize(TModel model);

		protected internal override void Initialize(BaseModel model)
		{
			DoInitialize((TModel)model);
		}
	}

	public class ViewModelActionExtension<TModel> : ViewModelExtension<TModel> where TModel : BaseModel
	{
		private readonly Action<TModel> InitAction;

		public ViewModelActionExtension(Action<TModel> initAction)
		{
			InitAction = initAction;
		}

		protected internal override void DoInitialize(TModel model)
		{
			InitAction(model);
		}
	}
}
